home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 8 / The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO / g_quake / gravity2.zip / WEAPONS.QC < prev   
Text File  |  1996-08-26  |  30KB  |  1,376 lines

  1. /*
  2. */
  3. void (entity targ, entity inflictor, entity attacker, float damage) T_Damage;
  4. void () player_run;
  5. void(entity bomb, entity attacker, float rad, entity ignore) T_RadiusDamage;
  6. void(vector org, vector vel, float damage) SpawnBlood;
  7. void() SuperDamageSound;
  8.  
  9.  
  10. // called by worldspawn
  11. void() W_Precache =
  12. {
  13.     precache_sound ("weapons/r_exp3.wav");    // new rocket explosion
  14.     precache_sound ("weapons/rocket1i.wav");    // spike gun
  15.     precache_sound ("weapons/sgun1.wav");
  16.     precache_sound ("weapons/guncock.wav");    // player shotgun
  17.     precache_sound ("weapons/ric1.wav");    // ricochet (used in c code)
  18.     precache_sound ("weapons/ric2.wav");    // ricochet (used in c code)
  19.     precache_sound ("weapons/ric3.wav");    // ricochet (used in c code)
  20.     precache_sound ("weapons/spike2.wav");    // super spikes
  21.     precache_sound ("weapons/tink1.wav");    // spikes tink (used in c code)
  22.     precache_sound ("weapons/grenade.wav");    // grenade launcher
  23.     precache_sound ("weapons/bounce.wav");        // grenade bounce
  24.     precache_sound ("weapons/shotgn2.wav");    // super shotgun
  25.         precache_model ("progs/flame2.mdl");
  26.  
  27. };
  28.  
  29. float() crandom =
  30. {
  31.     return 2*(random() - 0.5);
  32. };
  33.  
  34. /*
  35. ================
  36. W_FireAxe(Modified to gibbable to make up for loss of 'proper' grenades...)
  37. ================
  38. */
  39. void() W_FireAxe =
  40. {
  41.     local    vector    source;
  42.     local    vector    org;
  43.  
  44.     source = self.origin + '0 0 16';
  45.     traceline (source, source + v_forward*64, FALSE, self);
  46.     if (trace_fraction == 1.0)
  47.         return;
  48.     
  49.     org = trace_endpos - v_forward*4;
  50.  
  51.     if (trace_ent.takedamage)
  52.     {
  53.         trace_ent.axhitme = 1;
  54.         SpawnBlood (org, '0 0 0', 20);
  55.                 T_Damage (trace_ent, self, self, 150);
  56.     }
  57.     else
  58.     {    // hit wall
  59.         sound (self, CHAN_WEAPON, "player/axhit2.wav", 1, ATTN_NORM);
  60.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  61.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  62.         WriteCoord (MSG_BROADCAST, org_x);
  63.         WriteCoord (MSG_BROADCAST, org_y);
  64.         WriteCoord (MSG_BROADCAST, org_z);
  65.     }
  66. };
  67.  
  68.  
  69. //============================================================================
  70.  
  71.  
  72. vector() wall_velocity =
  73. {
  74.     local vector    vel;
  75.     
  76.     vel = normalize (self.velocity);
  77.     vel = normalize(vel + v_up*(random()- 0.5) + v_right*(random()- 0.5));
  78.     vel = vel + 2*trace_plane_normal;
  79.     vel = vel * 200;
  80.     
  81.     return vel;
  82. };
  83.  
  84.  
  85. /*
  86. ================
  87. SpawnMeatSpray
  88. ================
  89. */
  90. void(vector org, vector vel) SpawnMeatSpray =
  91. {
  92.     local    entity missile, mpuff;
  93.     local    vector    org;
  94.  
  95.     missile = spawn ();
  96.     missile.owner = self;
  97.     missile.movetype = MOVETYPE_BOUNCE;
  98.     missile.solid = SOLID_NOT;
  99.  
  100.     makevectors (self.angles);
  101.  
  102.     missile.velocity = vel;
  103.     missile.velocity_z = missile.velocity_z + 250 + 50*random();
  104.  
  105.     missile.avelocity = '3000 1000 2000';
  106.     
  107. // set missile duration
  108.     missile.nextthink = time + 1;
  109.     missile.think = SUB_Remove;
  110.  
  111.     setmodel (missile, "progs/zom_gib.mdl");
  112.     setsize (missile, '0 0 0', '0 0 0');        
  113.     setorigin (missile, org);
  114. };
  115.  
  116. /*
  117. ================
  118. SpawnBlood
  119. ================
  120. */
  121. void(vector org, vector vel, float damage) SpawnBlood =
  122. {
  123.     particle (org, vel*0.1, 73, damage*2);
  124. };
  125.  
  126. /*
  127. ================
  128. spawn_touchblood
  129. ================
  130. */
  131. void(float damage) spawn_touchblood =
  132. {
  133.     local vector    vel;
  134.  
  135.     vel = wall_velocity () * 0.2;
  136.     SpawnBlood (self.origin + vel*0.01, vel, damage);
  137. };
  138.  
  139.  
  140. /*
  141. ================
  142. SpawnChunk
  143. ================
  144. */
  145. void(vector org, vector vel) SpawnChunk =
  146. {
  147.     particle (org, vel*0.02, 0, 10);
  148. };
  149.  
  150. /*
  151. ==============================================================================
  152.  
  153. MULTI-DAMAGE
  154.  
  155. Collects multiple small damages into a single damage
  156.  
  157. ==============================================================================
  158. */
  159.  
  160. entity    multi_ent;
  161. float    multi_damage;
  162.  
  163. void() ClearMultiDamage =
  164. {
  165.     multi_ent = world;
  166.     multi_damage = 0;
  167. };
  168.  
  169. void() ApplyMultiDamage =
  170. {
  171.     if (!multi_ent)
  172.         return;
  173.     T_Damage (multi_ent, self, self, multi_damage);
  174. };
  175.  
  176. void(entity hit, float damage) AddMultiDamage =
  177. {
  178.     if (!hit)
  179.         return;
  180.     
  181.     if (hit != multi_ent)
  182.     {
  183.         ApplyMultiDamage ();
  184.         multi_damage = damage;
  185.         multi_ent = hit;
  186.     }
  187.     else
  188.         multi_damage = multi_damage + damage;
  189. };
  190.  
  191. /*
  192. ==============================================================================
  193.  
  194. BULLETS
  195.  
  196. ==============================================================================
  197. */
  198.  
  199. /*
  200. ================
  201. TraceAttack
  202. ================
  203. */
  204. void(float damage, vector dir) TraceAttack =
  205. {
  206.     local    vector    vel, org;
  207.     
  208.     vel = normalize(dir + v_up*crandom() + v_right*crandom());
  209.     vel = vel + 2*trace_plane_normal;
  210.     vel = vel * 200;
  211.  
  212.     org = trace_endpos - dir*4;
  213.  
  214.     if (trace_ent.takedamage)
  215.     {
  216.         SpawnBlood (org, vel*0.2, damage);
  217.         AddMultiDamage (trace_ent, damage);
  218.     }
  219.     else
  220.     {
  221.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  222.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  223.         WriteCoord (MSG_BROADCAST, org_x);
  224.         WriteCoord (MSG_BROADCAST, org_y);
  225.         WriteCoord (MSG_BROADCAST, org_z);
  226.     }
  227. };
  228.  
  229. /*
  230. ================
  231. FireBullets
  232.  
  233. Used by shotgun, super shotgun, and enemy soldier firing
  234. Go to the trouble of combining multiple pellets into a single damage call.
  235. ================
  236. */
  237. void(float shotcount, vector dir, vector spread) FireBullets =
  238. {
  239.     local    vector direction;
  240.     local    vector    src;
  241.     
  242.     makevectors(self.v_angle);
  243.  
  244.     src = self.origin + v_forward*10;
  245.     src_z = self.absmin_z + self.size_z * 0.7;
  246.  
  247.     ClearMultiDamage ();
  248.     while (shotcount > 0)
  249.     {
  250.         direction = dir + crandom()*spread_x*v_right + crandom()*spread_y*v_up;
  251.  
  252.         traceline (src, src + direction*2048, FALSE, self);
  253.         if (trace_fraction != 1.0)
  254.             TraceAttack (4, direction);
  255.  
  256.         shotcount = shotcount - 1;
  257.     }
  258.     ApplyMultiDamage ();
  259. };
  260.  
  261. /*
  262. ================
  263. W_FireShotgun
  264. ================
  265. */
  266. void() W_FireShotgun =
  267. {
  268.     local vector dir;
  269.  
  270.     sound (self, CHAN_WEAPON, "weapons/guncock.wav", 1, ATTN_NORM);    
  271.  
  272.     self.punchangle_x = -15;
  273.     
  274.     self.currentammo = self.ammo_shells = self.ammo_shells - 1;
  275.     dir = aim (self, 100000);
  276.     FireBullets (6, dir, '0.04 0.04 0');
  277. };
  278.  
  279.  
  280. /*
  281. ================
  282. W_FireSuperShotgun
  283. ================
  284. */
  285. void() W_FireSuperShotgun =
  286. {
  287.     local vector dir;
  288.  
  289.     if (self.currentammo == 1)
  290.     {
  291.         W_FireShotgun ();
  292.         return;
  293.     }
  294.         
  295.     sound (self ,CHAN_WEAPON, "weapons/shotgn2.wav", 1, ATTN_NORM);    
  296.  
  297.     self.punchangle_x = -4;
  298.     
  299.     self.currentammo = self.ammo_shells = self.ammo_shells - 2;
  300.     dir = aim (self, 100000);
  301.     FireBullets (14, dir, '0.14 0.08 0');
  302. };
  303.  
  304.  
  305. /*
  306. ==============================================================================
  307.  
  308. ROCKETS
  309.  
  310. ==============================================================================
  311. */
  312.  
  313. void()    s_explode1    =    [0,        s_explode2] {};
  314. void()    s_explode2    =    [1,        s_explode3] {};
  315. void()    s_explode3    =    [2,        s_explode4] {};
  316. void()    s_explode4    =    [3,        s_explode5] {};
  317. void()    s_explode5    =    [4,        s_explode6] {};
  318. void()    s_explode6    =    [5,        SUB_Remove] {};
  319.  
  320. void() BecomeExplosion =
  321. {
  322.     self.movetype = MOVETYPE_NONE;
  323.     self.velocity = '0 0 0';
  324.     self.touch = SUB_Null;
  325.     setmodel (self, "progs/s_explod.spr");
  326.     self.solid = SOLID_NOT;
  327.     s_explode1 ();
  328. };
  329.  
  330. void() T_MissileTouch =
  331. {
  332.     local float    damg;
  333.  
  334.     if (other == self.owner)
  335.         return;        // don't explode on owner
  336.  
  337.     if (pointcontents(self.origin) == CONTENT_SKY)
  338.     {
  339.         remove(self);
  340.         return;
  341.     }
  342.  
  343.     damg = 100 + random()*20;
  344.     
  345.     if (other.health)
  346.     {
  347.         if (other.classname == "monster_shambler")
  348.             damg = damg * 0.5;    // mostly immune
  349.         T_Damage (other, self, self.owner, damg );
  350.     }
  351.  
  352.     // don't do radius damage to the other, because all the damage
  353.     // was done in the impact
  354.     T_RadiusDamage (self, self.owner, 120, other);
  355.  
  356. //    sound (self, CHAN_WEAPON, "weapons/r_exp3.wav", 1, ATTN_NORM);
  357.     self.origin = self.origin - 8*normalize(self.velocity);
  358.  
  359.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  360.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  361.     WriteCoord (MSG_BROADCAST, self.origin_x);
  362.     WriteCoord (MSG_BROADCAST, self.origin_y);
  363.     WriteCoord (MSG_BROADCAST, self.origin_z);
  364.  
  365.     BecomeExplosion ();
  366. };
  367.  
  368.  
  369.  
  370. /*
  371. ================
  372. W_FireRocket
  373. ================
  374. */
  375. void() W_FireRocket =
  376. {
  377.     local    entity missile, mpuff;
  378.     
  379.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  380.     
  381.     sound (self, CHAN_WEAPON, "weapons/sgun1.wav", 1, ATTN_NORM);
  382.  
  383.     self.punchangle_x = -2;
  384.  
  385.     missile = spawn ();
  386.     missile.owner = self;
  387.     missile.movetype = MOVETYPE_FLYMISSILE;
  388.     missile.solid = SOLID_BBOX;
  389.         
  390. // set missile speed    
  391.  
  392.     makevectors (self.v_angle);
  393.     missile.velocity = aim(self, 1000);
  394.     missile.velocity = missile.velocity * 1000;
  395.     missile.angles = vectoangles(missile.velocity);
  396.     
  397.     missile.touch = T_MissileTouch;
  398.     
  399. // set missile duration
  400.     missile.nextthink = time + 5;
  401.     missile.think = SUB_Remove;
  402.  
  403.     setmodel (missile, "progs/missile.mdl");
  404.     setsize (missile, '0 0 0', '0 0 0');        
  405.     setorigin (missile, self.origin + v_forward*8 + '0 0 16');
  406. };
  407.  
  408. /*
  409. ===============================================================================
  410.  
  411. LIGHTNING
  412.  
  413. ===============================================================================
  414. */
  415.  
  416. /*
  417. =================
  418. LightningDamage
  419. =================
  420. */
  421. void(vector p1, vector p2, entity from, float damage) LightningDamage =
  422. {
  423.     local entity        e1, e2;
  424.     local vector        f;
  425.     
  426.     f = p2 - p1;
  427.     normalize (f);
  428.     f_x = 0 - f_y;
  429.     f_y = f_x;
  430.     f_z = 0;
  431.     f = f*16;
  432.  
  433.     e1 = e2 = world;
  434.  
  435.     traceline (p1, p2, FALSE, self);
  436.     if (trace_ent.takedamage)
  437.     {
  438.         particle (trace_endpos, '0 0 100', 225, damage*4);
  439.         T_Damage (trace_ent, from, from, damage);
  440.         if (self.classname == "player")
  441.         {
  442.             if (other.classname == "player")
  443.                 trace_ent.velocity_z = trace_ent.velocity_z + 400;
  444.         }
  445.     }
  446.     e1 = trace_ent;
  447.  
  448.     traceline (p1 + f, p2 + f, FALSE, self);
  449.     if (trace_ent != e1 && trace_ent.takedamage)
  450.     {
  451.         particle (trace_endpos, '0 0 100', 225, damage*4);
  452.         T_Damage (trace_ent, from, from, damage);
  453.     }
  454.     e2 = trace_ent;
  455.  
  456.     traceline (p1 - f, p2 - f, FALSE, self);
  457.     if (trace_ent != e1 && trace_ent != e2 && trace_ent.takedamage)
  458.     {
  459.         particle (trace_endpos, '0 0 100', 225, damage*4);
  460.         T_Damage (trace_ent, from, from, damage);
  461.     }
  462. };
  463.  
  464.  
  465. void() W_FireLightning =
  466. {
  467.     local    vector        org;
  468.  
  469.     if (self.ammo_cells < 1)
  470.     {
  471.         self.weapon = W_BestWeapon ();
  472.         W_SetCurrentAmmo ();
  473.         return;
  474.     }
  475.  
  476. // explode if under water
  477.     if (self.waterlevel > 1)
  478.     {
  479.         T_RadiusDamage (self, self, 35*self.ammo_cells, world);
  480.         self.ammo_cells = 0;
  481.         W_SetCurrentAmmo ();
  482.         return;
  483.     }
  484.  
  485.     if (self.t_width < time)
  486.     {
  487.         sound (self, CHAN_WEAPON, "weapons/lhit.wav", 1, ATTN_NORM);
  488.         self.t_width = time + 0.6;
  489.     }
  490.     self.punchangle_x = -2;
  491.  
  492.     self.currentammo = self.ammo_cells = self.ammo_cells - 1;
  493.  
  494.     org = self.origin + '0 0 16';
  495.     
  496.     traceline (org, org + v_forward*600, TRUE, self);
  497.  
  498.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  499.     WriteByte (MSG_BROADCAST, TE_LIGHTNING2);
  500.     WriteEntity (MSG_BROADCAST, self);
  501.     WriteCoord (MSG_BROADCAST, org_x);
  502.     WriteCoord (MSG_BROADCAST, org_y);
  503.     WriteCoord (MSG_BROADCAST, org_z);
  504.     WriteCoord (MSG_BROADCAST, trace_endpos_x);
  505.     WriteCoord (MSG_BROADCAST, trace_endpos_y);
  506.     WriteCoord (MSG_BROADCAST, trace_endpos_z);
  507.  
  508.     LightningDamage (self.origin, trace_endpos + v_forward*4, self, 30);
  509. };
  510.  
  511.  
  512. //=============================================================================
  513. //Start Gravity 2.0 Changes... (except for the declaration at top)
  514. //=============================================================================
  515. void(entity en) UnBounce =
  516. {
  517.         local string old;
  518.  
  519.         old = ftos(oldgrav);
  520.     other = find (world, classname, "player");
  521.     while (other != world)
  522.     {
  523.                 other.movetype = MOVETYPE_WALK;
  524.  
  525.         other = find (other, classname, "player");
  526.     }    
  527.         localcmd("sv_gravity ");
  528.         localcmd(old);
  529.         localcmd("\n");
  530.     self.nextthink = time + 0.1;
  531.         self.think = SUB_Remove;
  532.         bouncing = 0;
  533.  
  534. };
  535.  
  536. void() GravShift =
  537. {
  538.         local    string st;
  539.         local    float  pad;
  540.     local    float  inter;
  541.         local    entity bounc;
  542.  
  543.         pad = cvar("sv_gravity");
  544.  
  545.         inter = random();
  546.         if (inter > 0.8)
  547.         {
  548.                 pad = inter * 3000;
  549.         }
  550.         else
  551.         {
  552.                 if (inter < 0.43)
  553.                 {
  554.                         pad = (inter * 750) + 1;
  555.                       
  556.                 }
  557.                 else
  558.                 {
  559.                         pad = inter * 1500;
  560.                 }
  561.         }
  562.  
  563.         if (pad < 350)
  564.         {
  565.           bounc = spawn ();
  566.           bounc.owner = self;
  567.           bounc.movetype = MOVETYPE_NONE;
  568.           bounc.solid = SOLID_NOT;
  569.           bounc.classname = "GravGen";
  570.           bouncing = 1;
  571.  
  572.           other = find (world, classname, "player");
  573.                 while (other != world)
  574.                 {
  575.                         makevectors (other.v_angle);
  576.                 
  577.                         local vector start, end;
  578.          
  579.                         if (other.flags & FL_WATERJUMP)
  580.                                 break;
  581.                         
  582.                         if (other.waterlevel >= 2)
  583.                         {
  584.                                 if (other.watertype == CONTENT_WATER)
  585.                                         other.velocity_z = 100;
  586.                                 else if (self.watertype == CONTENT_SLIME)
  587.                                         other.velocity_z = 80;
  588.                                 else
  589.                                         other.velocity_z = 50;
  590.  
  591.                 // play swiming sound
  592.                                 if (other.swim_flag < time)
  593.                                 {
  594.                                         other.swim_flag = time + 1;
  595.                                         if (random() < 0.5)
  596.                                                 sound (other, CHAN_BODY, "misc/water1.wav", 1, ATTN_NORM);
  597.                                         else
  598.                                                 sound (other, CHAN_BODY, "misc/water2.wav", 1, ATTN_NORM);
  599.                                 }
  600.                 
  601.                                 break;
  602.                         }
  603.                         if (!(other.flags & FL_ONGROUND))
  604.                                 break;
  605.  
  606.                         if ( !(other.flags & FL_JUMPRELEASED) )
  607.                                 break;         // don't pogo stick
  608.                
  609.                         other.flags = other.flags - (other.flags & FL_JUMPRELEASED);
  610.  
  611.                         other.flags = other.flags - FL_ONGROUND;  // don't stairwalk
  612.     
  613.                         //other.button2 = 0;
  614.                 // player jumping sound
  615.                         sound (self, CHAN_BODY, "player/plyrjmp8.wav", 1, ATTN_NORM);
  616.                         other.velocity_z = other.velocity_z + 270;
  617.                         other.velocity_x = other.velocity_x - 270;
  618.                         other.velocity_y = other.velocity_y - 270;
  619.  
  620.                         other.movetype = MOVETYPE_BOUNCE;
  621.                         other = find (other, classname, "player");
  622.                 
  623.                 }
  624.  
  625.       oldgrav = pad;
  626.       pad = 0;
  627.  
  628.           bounc.nextthink = time + 30;
  629.           bounc.think = UnBounce;
  630.           bounc.effects=EF_MUZZLEFLASH;
  631.           bounc.style=0;
  632.           bounc.frame=0;
  633.           setmodel(bounc,"progs/flame2.mdl");
  634.           setsize(bounc,'0 0 0','0 0 0');
  635.           setorigin(bounc,self.origin+'0 0 16');
  636.  
  637.         }
  638.         else
  639.         {
  640.                 other = find (world, classname, "player");
  641.                 while (other != world)
  642.                 {
  643.                         other.movetype = MOVETYPE_WALK;
  644.                         
  645.                         other = find (other, classname, "player");
  646.                 }
  647.         }
  648.  
  649.  
  650.  
  651.         st = ftos(pad);
  652.         localcmd("sv_gravity ");
  653.         localcmd(st);
  654.         localcmd("\n");
  655.  
  656. };
  657.  
  658. void() GrenadeExplode =
  659. {
  660.      if(bouncing != 1)
  661.      {   
  662.     T_RadiusDamage (self, self.owner, 0, world);
  663.  
  664.     GravShift();
  665.      }
  666.      else
  667.         T_RadiusDamage (self, self.owner, 120, world);
  668.  
  669.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  670.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  671.     WriteCoord (MSG_BROADCAST, self.origin_x);
  672.     WriteCoord (MSG_BROADCAST, self.origin_y);
  673.     WriteCoord (MSG_BROADCAST, self.origin_z);
  674.  
  675.     BecomeExplosion ();
  676. };
  677.  
  678. void() GrenadeTouch =
  679. {
  680.     if (other == self.owner)
  681.         return;        // don't explode on owner
  682.     if (other.takedamage == DAMAGE_AIM)
  683.     {
  684.         GrenadeExplode();
  685.         return;
  686.     }
  687.     sound (self, CHAN_WEAPON, "weapons/bounce.wav", 1, ATTN_NORM);    // bounce sound
  688.     if (self.velocity == '0 0 0')
  689.         self.avelocity = '0 0 0';
  690. };
  691.  
  692. /*
  693. ================
  694. W_FireGrenade
  695. ================
  696. */
  697. void() W_FireGrenade =
  698. {
  699.     local    entity missile, mpuff;
  700.     
  701.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  702.     
  703.     sound (self, CHAN_WEAPON, "weapons/grenade.wav", 1, ATTN_NORM);
  704.  
  705.     self.punchangle_x = -2;
  706.  
  707.     missile = spawn ();
  708.     missile.owner = self;
  709.     missile.movetype = MOVETYPE_BOUNCE;
  710.     missile.solid = SOLID_BBOX;
  711.     missile.classname = "grenade";
  712.         
  713. // set missile speed    
  714.  
  715.     makevectors (self.v_angle);
  716.  
  717.     if (self.v_angle_x)
  718.         missile.velocity = v_forward*600 + v_up * 200 + crandom()*v_right*10 + crandom()*v_up*10;
  719.     else
  720.     {
  721.         missile.velocity = aim(self, 10000);
  722.         missile.velocity = missile.velocity * 600;
  723.         missile.velocity_z = 200;
  724.     }
  725.  
  726.     missile.avelocity = '300 300 300';
  727.  
  728.     missile.angles = vectoangles(missile.velocity);
  729.     
  730.     missile.touch = GrenadeTouch;
  731.     
  732. // set missile duration
  733.     missile.nextthink = time + 2.5;
  734.     missile.think = GrenadeExplode;
  735.  
  736.     setmodel (missile, "progs/grenade.mdl");
  737.     setsize (missile, '0 0 0', '0 0 0');        
  738.     setorigin (missile, self.origin);
  739. };
  740.  
  741.  
  742. //=============================================================================
  743. //End Changes for Gravity Grenade 2.0
  744. //=============================================================================
  745.  
  746. void() spike_touch;
  747. void() superspike_touch;
  748.  
  749.  
  750. /*
  751. ===============
  752. launch_spike
  753.  
  754. Used for both the player and the ogre
  755. ===============
  756. */
  757. void(vector org, vector dir) launch_spike =
  758. {
  759.     newmis = spawn ();
  760.     newmis.owner = self;
  761.     newmis.movetype = MOVETYPE_FLYMISSILE;
  762.     newmis.solid = SOLID_BBOX;
  763.  
  764.     newmis.angles = vectoangles(dir);
  765.     
  766.     newmis.touch = spike_touch;
  767.     newmis.classname = "spike";
  768.     newmis.think = SUB_Remove;
  769.     newmis.nextthink = time + 6;
  770.     setmodel (newmis, "progs/spike.mdl");
  771.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);        
  772.     setorigin (newmis, org);
  773.  
  774.     newmis.velocity = dir * 1000;
  775. };
  776.  
  777. void() W_FireSuperSpikes =
  778. {
  779.     local vector    dir;
  780.     local entity    old;
  781.     
  782.     sound (self, CHAN_WEAPON, "weapons/spike2.wav", 1, ATTN_NORM);
  783.     self.attack_finished = time + 0.2;
  784.     self.currentammo = self.ammo_nails = self.ammo_nails - 2;
  785.     dir = aim (self, 1000);
  786.     launch_spike (self.origin + '0 0 16', dir);
  787.     newmis.touch = superspike_touch;
  788.     setmodel (newmis, "progs/s_spike.mdl");
  789.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);        
  790.     self.punchangle_x = -2;
  791. };
  792.  
  793. void(float ox) W_FireSpikes =
  794. {
  795.     local vector    dir;
  796.     local entity    old;
  797.     
  798.     makevectors (self.v_angle);
  799.     
  800.     if (self.ammo_nails >= 2 && self.weapon == IT_SUPER_NAILGUN)
  801.     {
  802.         W_FireSuperSpikes ();
  803.         return;
  804.     }
  805.  
  806.     if (self.ammo_nails < 1)
  807.     {
  808.         self.weapon = W_BestWeapon ();
  809.         W_SetCurrentAmmo ();
  810.         return;
  811.     }
  812.  
  813.     sound (self, CHAN_WEAPON, "weapons/rocket1i.wav", 1, ATTN_NORM);
  814.     self.attack_finished = time + 0.2;
  815.     self.currentammo = self.ammo_nails = self.ammo_nails - 1;
  816.     dir = aim (self, 1000);
  817.     launch_spike (self.origin + '0 0 16' + v_right*ox, dir);
  818.  
  819.     self.punchangle_x = -2;
  820. };
  821.  
  822.  
  823.  
  824. .float hit_z;
  825. void() spike_touch =
  826. {
  827. local float rand;
  828.     if (other == self.owner)
  829.         return;
  830.  
  831.     if (other.solid == SOLID_TRIGGER)
  832.         return;    // trigger field, do nothing
  833.  
  834.     if (pointcontents(self.origin) == CONTENT_SKY)
  835.     {
  836.         remove(self);
  837.         return;
  838.     }
  839.     
  840. // hit something that bleeds
  841.     if (other.takedamage)
  842.     {
  843.         spawn_touchblood (9);
  844.         T_Damage (other, self, self.owner, 9);
  845.     }
  846.     else
  847.     {
  848.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  849.         
  850.         if (self.classname == "wizspike")
  851.             WriteByte (MSG_BROADCAST, TE_WIZSPIKE);
  852.         else if (self.classname == "knightspike")
  853.             WriteByte (MSG_BROADCAST, TE_KNIGHTSPIKE);
  854.         else
  855.             WriteByte (MSG_BROADCAST, TE_SPIKE);
  856.         WriteCoord (MSG_BROADCAST, self.origin_x);
  857.         WriteCoord (MSG_BROADCAST, self.origin_y);
  858.         WriteCoord (MSG_BROADCAST, self.origin_z);
  859.     }
  860.  
  861.     remove(self);
  862.  
  863. };
  864.  
  865. void() superspike_touch =
  866. {
  867. local float rand;
  868.     if (other == self.owner)
  869.         return;
  870.  
  871.     if (other.solid == SOLID_TRIGGER)
  872.         return;    // trigger field, do nothing
  873.  
  874.     if (pointcontents(self.origin) == CONTENT_SKY)
  875.     {
  876.         remove(self);
  877.         return;
  878.     }
  879.     
  880. // hit something that bleeds
  881.     if (other.takedamage)
  882.     {
  883.         spawn_touchblood (18);
  884.         T_Damage (other, self, self.owner, 18);
  885.     }
  886.     else
  887.     {
  888.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  889.         WriteByte (MSG_BROADCAST, TE_SUPERSPIKE);
  890.         WriteCoord (MSG_BROADCAST, self.origin_x);
  891.         WriteCoord (MSG_BROADCAST, self.origin_y);
  892.         WriteCoord (MSG_BROADCAST, self.origin_z);
  893.     }
  894.  
  895.     remove(self);
  896.  
  897. };
  898.  
  899.  
  900. /*
  901. ===============================================================================
  902.  
  903. PLAYER WEAPON USE
  904.  
  905. ===============================================================================
  906. */
  907.  
  908. void() W_SetCurrentAmmo =
  909. {
  910.     player_run ();        // get out of any weapon firing states
  911.  
  912.     self.items = self.items - ( self.items & (IT_SHELLS | IT_NAILS | IT_ROCKETS | IT_CELLS) );
  913.     
  914.     if (self.weapon == IT_AXE)
  915.     {
  916.         self.currentammo = 0;
  917.         self.weaponmodel = "progs/v_axe.mdl";
  918.         self.weaponframe = 0;
  919.     }
  920.     else if (self.weapon == IT_SHOTGUN)
  921.     {
  922.         self.currentammo = self.ammo_shells;
  923.         self.weaponmodel = "progs/v_shot.mdl";
  924.         self.weaponframe = 0;
  925.         self.items = self.items | IT_SHELLS;
  926.     }
  927.     else if (self.weapon == IT_SUPER_SHOTGUN)
  928.     {
  929.         self.currentammo = self.ammo_shells;
  930.         self.weaponmodel = "progs/v_shot2.mdl";
  931.         self.weaponframe = 0;
  932.         self.items = self.items | IT_SHELLS;
  933.     }
  934.     else if (self.weapon == IT_NAILGUN)
  935.     {
  936.         self.currentammo = self.ammo_nails;
  937.         self.weaponmodel = "progs/v_nail.mdl";
  938.         self.weaponframe = 0;
  939.         self.items = self.items | IT_NAILS;
  940.     }
  941.     else if (self.weapon == IT_SUPER_NAILGUN)
  942.     {
  943.         self.currentammo = self.ammo_nails;
  944.         self.weaponmodel = "progs/v_nail2.mdl";
  945.         self.weaponframe = 0;
  946.         self.items = self.items | IT_NAILS;
  947.     }
  948.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  949.     {
  950.         self.currentammo = self.ammo_rockets;
  951.         self.weaponmodel = "progs/v_rock.mdl";
  952.         self.weaponframe = 0;
  953.         self.items = self.items | IT_ROCKETS;
  954.     }
  955.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  956.     {
  957.         self.currentammo = self.ammo_rockets;
  958.         self.weaponmodel = "progs/v_rock2.mdl";
  959.         self.weaponframe = 0;
  960.         self.items = self.items | IT_ROCKETS;
  961.     }
  962.     else if (self.weapon == IT_LIGHTNING)
  963.     {
  964.         self.currentammo = self.ammo_cells;
  965.         self.weaponmodel = "progs/v_light.mdl";
  966.         self.weaponframe = 0;
  967.         self.items = self.items | IT_CELLS;
  968.     }
  969.     else
  970.     {
  971.         self.currentammo = 0;
  972.         self.weaponmodel = "";
  973.         self.weaponframe = 0;
  974.     }
  975. };
  976.  
  977. float() W_BestWeapon =
  978. {
  979.     local    float    it;
  980.     
  981.     it = self.items;
  982.  
  983.     if(self.ammo_cells >= 1 && (it & IT_LIGHTNING) )
  984.         return IT_LIGHTNING;
  985.     else if(self.ammo_nails >= 2 && (it & IT_SUPER_NAILGUN) )
  986.         return IT_SUPER_NAILGUN;
  987.     else if(self.ammo_shells >= 2 && (it & IT_SUPER_SHOTGUN) )
  988.         return IT_SUPER_SHOTGUN;
  989.     else if(self.ammo_nails >= 1 && (it & IT_NAILGUN) )
  990.         return IT_NAILGUN;
  991.     else if(self.ammo_shells >= 1 && (it & IT_SHOTGUN) )
  992.         return IT_SHOTGUN;
  993.         
  994. /*
  995.     if(self.ammo_rockets >= 1 && (it & IT_ROCKET_LAUNCHER) )
  996.         return IT_ROCKET_LAUNCHER;
  997.     else if(self.ammo_rockets >= 1 && (it & IT_GRENADE_LAUNCHER) )
  998.         return IT_GRENADE_LAUNCHER;
  999.  
  1000. */
  1001.  
  1002.     return IT_AXE;
  1003. };
  1004.  
  1005. float() W_CheckNoAmmo =
  1006. {
  1007.     if (self.currentammo > 0)
  1008.         return TRUE;
  1009.  
  1010.     if (self.weapon == IT_AXE)
  1011.         return TRUE;
  1012.     
  1013.     self.weapon = W_BestWeapon ();
  1014.  
  1015.     W_SetCurrentAmmo ();
  1016.     
  1017. // drop the weapon down
  1018.     return FALSE;
  1019. };
  1020.  
  1021. /*
  1022. ============
  1023. W_Attack
  1024.  
  1025. An attack impulse can be triggered now
  1026. ============
  1027. */
  1028. void()    player_axe1;
  1029. void()    player_axeb1;
  1030. void()    player_axec1;
  1031. void()    player_axed1;
  1032. void()    player_shot1;
  1033. void()    player_nail1;
  1034. void()    player_light1;
  1035. void()    player_rocket1;
  1036.  
  1037. void() W_Attack =
  1038. {
  1039.     local    float    r;
  1040.  
  1041.     if (!W_CheckNoAmmo ())
  1042.         return;
  1043.  
  1044.     makevectors    (self.v_angle);            // calculate forward angle for velocity
  1045.     self.show_hostile = time + 1;    // wake monsters up
  1046.  
  1047.     if (self.weapon == IT_AXE)
  1048.     {
  1049.         sound (self, CHAN_WEAPON, "weapons/ax1.wav", 1, ATTN_NORM);
  1050.         r = random();
  1051.         if (r < 0.25)
  1052.             player_axe1 ();
  1053.         else if (r<0.5)
  1054.             player_axeb1 ();
  1055.         else if (r<0.75)
  1056.             player_axec1 ();
  1057.         else
  1058.             player_axed1 ();
  1059.         self.attack_finished = time + 0.5;
  1060.     }
  1061.     else if (self.weapon == IT_SHOTGUN)
  1062.     {
  1063.         player_shot1 ();
  1064.         W_FireShotgun ();
  1065.         self.attack_finished = time + 0.5;
  1066.     }
  1067.     else if (self.weapon == IT_SUPER_SHOTGUN)
  1068.     {
  1069.         player_shot1 ();
  1070.         W_FireSuperShotgun ();
  1071.         self.attack_finished = time + 0.7;
  1072.     }
  1073.     else if (self.weapon == IT_NAILGUN)
  1074.     {
  1075.         player_nail1 ();
  1076.     }
  1077.     else if (self.weapon == IT_SUPER_NAILGUN)
  1078.     {
  1079.         player_nail1 ();
  1080.     }
  1081.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  1082.     {
  1083.         player_rocket1();
  1084.         W_FireGrenade();
  1085.         self.attack_finished = time + 0.6;
  1086.     }
  1087.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  1088.     {
  1089.         player_rocket1();
  1090.         W_FireRocket();
  1091.         self.attack_finished = time + 0.8;
  1092.     }
  1093.     else if (self.weapon == IT_LIGHTNING)
  1094.     {
  1095.         player_light1();
  1096.         self.attack_finished = time + 0.1;
  1097.         sound (self, CHAN_AUTO, "weapons/lstart.wav", 1, ATTN_NORM);
  1098.     }
  1099. };
  1100.  
  1101. /*
  1102. ============
  1103. W_ChangeWeapon
  1104.  
  1105. ============
  1106. */
  1107. void() W_ChangeWeapon =
  1108. {
  1109.     local    float    it, am, fl;
  1110.     
  1111.     it = self.items;
  1112.     am = 0;
  1113.     
  1114.     if (self.impulse == 1)
  1115.     {
  1116.         fl = IT_AXE;
  1117.     }
  1118.     else if (self.impulse == 2)
  1119.     {
  1120.         fl = IT_SHOTGUN;
  1121.         if (self.ammo_shells < 1)
  1122.             am = 1;
  1123.     }
  1124.     else if (self.impulse == 3)
  1125.     {
  1126.         fl = IT_SUPER_SHOTGUN;
  1127.         if (self.ammo_shells < 2)
  1128.             am = 1;
  1129.     }        
  1130.     else if (self.impulse == 4)
  1131.     {
  1132.         fl = IT_NAILGUN;
  1133.         if (self.ammo_nails < 1)
  1134.             am = 1;
  1135.     }
  1136.     else if (self.impulse == 5)
  1137.     {
  1138.         fl = IT_SUPER_NAILGUN;
  1139.         if (self.ammo_nails < 2)
  1140.             am = 1;
  1141.     }
  1142.     else if (self.impulse == 6)
  1143.     {
  1144.         fl = IT_GRENADE_LAUNCHER;
  1145.         if (self.ammo_rockets < 1)
  1146.             am = 1;
  1147.     }
  1148.     else if (self.impulse == 7)
  1149.     {
  1150.         fl = IT_ROCKET_LAUNCHER;
  1151.         if (self.ammo_rockets < 1)
  1152.             am = 1;
  1153.     }
  1154.     else if (self.impulse == 8)
  1155.     {
  1156.         fl = IT_LIGHTNING;
  1157.         if (self.ammo_cells < 1)
  1158.             am = 1;
  1159.     }
  1160.  
  1161.     self.impulse = 0;
  1162.     
  1163.     if (!(self.items & fl))
  1164.     {    // don't have the weapon or the ammo
  1165.         sprint (self, "no weapon.\n");
  1166.         return;
  1167.     }
  1168.     
  1169.     if (am)
  1170.     {    // don't have the ammo
  1171.         sprint (self, "not enough ammo.\n");
  1172.         return;
  1173.     }
  1174.  
  1175. //
  1176. // set weapon, set ammo
  1177. //
  1178.     self.weapon = fl;        
  1179.     W_SetCurrentAmmo ();
  1180. };
  1181.  
  1182. /*
  1183. ============
  1184. CheatCommand
  1185. ============
  1186. */
  1187. void() CheatCommand =
  1188. {
  1189.     if (deathmatch || coop)
  1190.         return;
  1191.  
  1192.     self.ammo_rockets = 100;
  1193.     self.ammo_nails = 200;
  1194.     self.ammo_shells = 100;
  1195.     self.items = self.items | 
  1196.         IT_AXE |
  1197.         IT_SHOTGUN |
  1198.         IT_SUPER_SHOTGUN |
  1199.         IT_NAILGUN |
  1200.         IT_SUPER_NAILGUN |
  1201.         IT_GRENADE_LAUNCHER |
  1202.         IT_ROCKET_LAUNCHER |
  1203.         IT_KEY1 | IT_KEY2;
  1204.  
  1205.     self.ammo_cells = 200;
  1206.     self.items = self.items | IT_LIGHTNING;
  1207.  
  1208.     self.weapon = IT_ROCKET_LAUNCHER;
  1209.     self.impulse = 0;
  1210.     W_SetCurrentAmmo ();
  1211. };
  1212.  
  1213. /*
  1214. ============
  1215. CycleWeaponCommand
  1216.  
  1217. Go to the next weapon with ammo
  1218. ============
  1219. */
  1220. void() CycleWeaponCommand =
  1221. {
  1222.     local    float    it, am;
  1223.     
  1224.     it = self.items;
  1225.     self.impulse = 0;
  1226.     
  1227.     while (1)
  1228.     {
  1229.         am = 0;
  1230.  
  1231.         if (self.weapon == IT_LIGHTNING)
  1232.         {
  1233.             self.weapon = IT_AXE;
  1234.         }
  1235.         else if (self.weapon == IT_AXE)
  1236.         {
  1237.             self.weapon = IT_SHOTGUN;
  1238.             if (self.ammo_shells < 1)
  1239.                 am = 1;
  1240.         }
  1241.         else if (self.weapon == IT_SHOTGUN)
  1242.         {
  1243.             self.weapon = IT_SUPER_SHOTGUN;
  1244.             if (self.ammo_shells < 2)
  1245.                 am = 1;
  1246.         }        
  1247.         else if (self.weapon == IT_SUPER_SHOTGUN)
  1248.         {
  1249.             self.weapon = IT_NAILGUN;
  1250.             if (self.ammo_nails < 1)
  1251.                 am = 1;
  1252.         }
  1253.         else if (self.weapon == IT_NAILGUN)
  1254.         {
  1255.             self.weapon = IT_SUPER_NAILGUN;
  1256.             if (self.ammo_nails < 2)
  1257.                 am = 1;
  1258.         }
  1259.         else if (self.weapon == IT_SUPER_NAILGUN)
  1260.         {
  1261.             self.weapon = IT_GRENADE_LAUNCHER;
  1262.             if (self.ammo_rockets < 1)
  1263.                 am = 1;
  1264.         }
  1265.         else if (self.weapon == IT_GRENADE_LAUNCHER)
  1266.         {
  1267.             self.weapon = IT_ROCKET_LAUNCHER;
  1268.             if (self.ammo_rockets < 1)
  1269.                 am = 1;
  1270.         }
  1271.         else if (self.weapon == IT_ROCKET_LAUNCHER)
  1272.         {
  1273.             self.weapon = IT_LIGHTNING;
  1274.             if (self.ammo_cells < 1)
  1275.                 am = 1;
  1276.         }
  1277.     
  1278.         if ( (self.items & self.weapon) && am == 0)
  1279.         {
  1280.             W_SetCurrentAmmo ();
  1281.             return;
  1282.         }
  1283.     }
  1284.  
  1285. };
  1286.  
  1287. /*
  1288. ============
  1289. ServerflagsCommand
  1290.  
  1291. Just for development
  1292. ============
  1293. */
  1294. void() ServerflagsCommand =
  1295. {
  1296.     serverflags = serverflags * 2 + 1;
  1297. };
  1298.  
  1299. void() QuadCheat =
  1300. {
  1301.     if (deathmatch || coop)
  1302.         return;
  1303.     self.super_time = 1;
  1304.     self.super_damage_finished = time + 30;
  1305.     self.items = self.items | IT_QUAD;
  1306.     dprint ("quad cheat\n");
  1307. };
  1308.  
  1309. /*
  1310. ============
  1311. ImpulseCommands
  1312.  
  1313. ============
  1314. */
  1315. void() ImpulseCommands =
  1316. {
  1317.     if (self.impulse >= 1 && self.impulse <= 8)
  1318.         W_ChangeWeapon ();
  1319.  
  1320.     if (self.impulse == 9)
  1321.         CheatCommand ();
  1322.     if (self.impulse == 10)
  1323.         CycleWeaponCommand ();
  1324.     if (self.impulse == 11)
  1325.         ServerflagsCommand ();
  1326.  
  1327.     if (self.impulse == 255)
  1328.         QuadCheat ();
  1329.         
  1330.     self.impulse = 0;
  1331. };
  1332.  
  1333. /*
  1334. ============
  1335. W_WeaponFrame
  1336.  
  1337. Called every frame so impulse events can be handled as well as possible
  1338. ============
  1339. */
  1340. void() W_WeaponFrame =
  1341. {
  1342.     if (time < self.attack_finished)
  1343.         return;
  1344.  
  1345.     ImpulseCommands ();
  1346.     
  1347. // check for attack
  1348.     if (self.button0)
  1349.     {
  1350.         SuperDamageSound ();
  1351.         W_Attack ();
  1352.     }
  1353. };
  1354.  
  1355. /*
  1356. ========
  1357. SuperDamageSound
  1358.  
  1359. Plays sound if needed
  1360. ========
  1361. */
  1362. void() SuperDamageSound =
  1363. {
  1364.     if (self.super_damage_finished > time)
  1365.     {
  1366.         if (self.super_sound < time)
  1367.         {
  1368.             self.super_sound = time + 1;
  1369.             sound (self, CHAN_BODY, "items/damage3.wav", 1, ATTN_NORM);
  1370.         }
  1371.     }
  1372.     return;
  1373. };
  1374.  
  1375.  
  1376.